package org.mzx.shortLink.adminn.service.handler.chain.userRegister;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.mzx.shortLink.adminn.domain.entity.TUser;
import org.mzx.shortLink.adminn.domain.mapper.TUserMapper;
import org.mzx.shortLink.adminn.dto.Request.TUserDtoReq;
import org.mzx.shortLink.adminn.service.TUserService;
import org.mzx.shortLink.starter.convention.Exception.ServiceException;
import org.springframework.stereotype.Component;

/**
 * @author mazhenxi
 * @date 2025/4/24
 */
@Component
@RequiredArgsConstructor
public class userRegisterCheckEmail implements userRegisterChain{

    private final TUserMapper tUserMapper;

    @Override
    public void handler(TUserDtoReq requestParam) {
        TUser user = tUserMapper.selectOne(Wrappers.lambdaQuery(TUser.class)
                                                    .eq(TUser::getMail, requestParam.getMail()));
        if (user!=null) {
            throw new ServiceException("该邮箱已经被绑定了，换一个邮箱注册吧");
        }
    }

    @Override
    public int getOrder() {
        return 30;
    }
}
